package com.easylive.web.controller;

import com.easylive.annotation.GlobalInterceptor;
import com.easylive.entity.constants.Constants;
import com.easylive.entity.enums.ResponseCodeEnum;
import com.easylive.entity.enums.VideoRecommendTypeEnum;
import com.easylive.entity.po.UserAction;
import com.easylive.entity.po.VideoInfo;
import com.easylive.entity.po.VideoInfoFile;
import com.easylive.entity.query.VideoInfoFileQuery;
import com.easylive.entity.query.VideoInfoQuery;
import com.easylive.entity.vo.PaginationResultVO;
import com.easylive.entity.vo.ResponseVO;
import com.easylive.entity.vo.VideoInfoResultVO;
import com.easylive.exception.BusinessException;
import com.easylive.service.UserActionService;
import com.easylive.service.VideoInfoFileService;
import com.easylive.service.VideoInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.*;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/userAction")
@Validated
public class UserActionController extends ABaseController{
    @Resource
    private VideoInfoService videoInfoService;
    @Resource
    private VideoInfoFileService videoInfoFileService;
    @Resource
    private UserActionService userActionService;


    @RequestMapping("/doAction")
    @GlobalInterceptor(checkLogin = true)
    public ResponseVO doAction(@NotEmpty String videoId,
                               @NotNull Integer actionType,
                               @Max(2) @Min(1) Integer acctionCount,
                               Integer commentId){
        UserAction userAction = new UserAction();
        userAction.setActionType(actionType);
        userAction.setVideoId(videoId);
        userAction.setCommentId(0);
        userAction.setUserId(getTokenUserInfoDto().getUserId());
        acctionCount = acctionCount == null ? Constants.ONE : acctionCount;
        userAction.setActionCount(acctionCount);
        if(commentId != null){
            userAction.setCommentId(commentId);
        }
        userActionService.saveAction(userAction);
        return getSuccessResponseVO(null);



    }



}
